#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :简繁体对照.py
# @Time      :2024/10/30 
# @Author    :CL
# @email     :1037654919@qq.com


def get_info():
    import requests

    headers = {
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Cache-Control": "no-cache",
        "Connection": "keep-alive",
        "Pragma": "no-cache",
        "Sec-Fetch-Dest": "document",
        "Sec-Fetch-Mode": "navigate",
        "Sec-Fetch-Site": "none",
        "Sec-Fetch-User": "?1",
        "Upgrade-Insecure-Requests": "1",
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
        "sec-ch-ua": "\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Linux\""
    }
    cookies = {
        "_ga": "GA1.1.1461385627.1729215826",
        "_ga_SRC3NVZE34": "GS1.1.1729231435.2.0.1729231435.0.0.0",
        "Hm_lvt_481e77a217efc98040c23f476554afef": "1729215565,1730268815",
        "HMACCOUNT": "8A7B5B515FA69801",
        "Hm_lpvt_481e77a217efc98040c23f476554afef": "1730272038"
    }
    url = "https://www.hanyuguoxue.com/zidian/jianfan"
    response = requests.get(url, headers=headers, cookies=cookies)

    # print(response.text)
    print(response.url,response)
    if response.status_code == 200:
        return response
from bs4 import BeautifulSoup
if __name__ == '__main__':
    print()
    data = get_info()
    # print(data.text)
    soup = BeautifulSoup(data.text, 'html.parser')
    data = soup.find('div',class_='content-list pb-3')
    # print(data)
    datas = data.find_all(name ='div',class_='content-card-body show')
    # print(datas[0])
    print(len(datas))
    with open ('简繁体对照.txt','w',encoding='utf-8') as f:
        for i in range(len(datas)):
            for li in datas[i].find_all('li'):
                print(li.text)
                f.write(li.text+'\n')
